<?php

namespace app\api\controller\driver;

use app\common\controller\Api;
use app\common\service\driver\DriverService;
use think\Validate;

/**
 * 司机端-收款码接口
 * @ApiWeigh (83)
 */
class Qrcode extends Api
{
    protected $beforeActionList = [
        'create_before' => ['only' => 'create'],
    ];
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * @ApiInternal
     */
    public function create_before()
    {
        $params = $this->request->post();
        if(empty($params['qrcode_wechat']) && empty($params['qrcode_alipay'])){
            $this->success('success');
        }
    }


    /**
     * 收款码
     *
     * @ApiMethod (POST)
     * @ApiReturnParams (name=data,type="object",description=要返回的数据)
     * @ApiReturn ({"code": 1,"msg": "收款码","time": "1721313320","data": {"driver_id": 1,"qrcode_wechat": "微信收款码","qrcode_alipay": "支付宝收款码"}})
     **/
    public function index()
    {
        $user = $this->auth->getUser();
        $this->success('收款码', DriverService::index_qrcode($user));
    }

    /**
     * 提交收款码
     *
     * @ApiMethod (POST)
     * @ApiParams (name="qrcode_wechat", type="string", required=false, description="微信收款码")
     * @ApiParams (name="qrcode_alipay", type="string", required=false, description="支付宝收款码")
     * @ApiReturnParams (name=data,type="object",description=要返回的数据)
     * @ApiReturn ({"code": 1,"msg": "提交成功","time": "1695260676","data": null})
     **/
    public function create()
    {
        $qrcode_wechat = $this->request->post('qrcode_wechat');
        $qrcode_alipay = $this->request->post('qrcode_alipay');
        $params = compact('qrcode_wechat','qrcode_alipay');
        $user = $this->auth->getUser();
        DriverService::create_qrcode($params, $user);
        $this->success('提交成功');
    }

}
